package com.dynamic.sync.toolkit.mongo.sync.request;

import com.dynamic.sync.toolkit.EnvType;
import java.util.List;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

/**
 * @author ZonLen since on 2021/6/19 下午8:51
 */
@Data
public class SyncSourceToTargetReq {

  private String sourceEnv;

  private String sourceCollectionName;

  private String sourceDocumentName;

  private List<String> groupPrimaryKey;

  private String targetEnv;

  private String targetCollectionName;

  private String targetDocumentName;

  public List<String> getGroupPrimaryKey() {
    if (CollectionUtils.isEmpty(groupPrimaryKey)){
      throw new RuntimeException("同步必须有业务唯一主键");
    }
    return groupPrimaryKey;
  }

  public EnvType sourceEnv() {
    if (sourceEnv == null || sourceEnv.equals(targetEnv)) {
      throw new RuntimeException("环境参数有问题");
    }
    return EnvType.valueOf(sourceEnv);
  }

  public EnvType targetEnv() {
    return EnvType.valueOf(targetEnv);
  }


}
